package LanQiao._14JavaB;

import java.util.Scanner;

//ps: 区间DP
//int[N][N][3] dp  从 i ~ j 对应color 合并所耗费的石头数
//dp[i][i][color] = 0;
//int[N][N] c  堆数DP转移
//int[N][N] w  根据c记录得到的题目要求的最少的合并所耗费石头数
public class _8合并石子 {

    static int N = 305;
    static int[] a = new int[N];
    static int[][][] dp = new int[N][N][3];
    static int[][] c = new int[N][N];
    static int[][] w = new int[N][N];
    static int INF = 1000000007;

    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        for (int i = 1; i <= n; i++) {
            a[i] = in.nextInt();
            a[i] += a[i - 1];
        }
        init(n);
        for (int i = 1; i <= n; i++) {
            int color = in.nextInt();
            dp[i][i][color] = 0;
        }

        for (int len = 1; len <= n; len++) {
            for (int L = 1; L+len-1 <= n; L++) {
                int R = L+len-1;

                for (int color = 0; color < 3; color++) {
                    int tmp = INF;
                    for (int k = L; k < R; k++) {
                        if (dp[L][k][color] != INF && dp[k + 1][R][color] != INF) {
                            //耗费数计算，注意审题！！
                            tmp = Math.min(tmp,dp[L][k][color] + dp[k + 1][R][color] + a[R] - a[L - 1]);
                        }
                    }

                    //状态转移
                    if (tmp != INF) {
                        c[L][R] = 1;
                        dp[L][R][(color + 1) % 3] = Math.min(tmp,dp[L][R][(color + 1) % 3]);
                        w[L][R] = Math.min(dp[L][R][(color + 1) % 3],w[L][R]);
                    }

                }

                for (int k = L; k < R; k++) {
                    if (c[L][R] > c[L][k] + c[k + 1][R]) {
                        c[L][R] = c[L][k] + c[k + 1][R];
                        w[L][R] = w[L][k] + w[k + 1][R];
                    }else if (c[L][R] == c[L][k] + c[k + 1][R]) {
                        w[L][R] = Math.min(w[L][R],w[L][k] + w[k + 1][R]);
                    }
                }
            }
        }
        System.out.println(c[1][n] + " " + w[1][n]);
        in.close();
    }

    public static void init(int n){
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                c[i][j] = j - i + 1;
                if (i != j) w[i][j] = INF;
                for (int color = 0; color < 3; color++) {
                    dp[i][j][color] = INF;
                }
            }
        }
    }
}
